package com.guge.sports.controller;


import com.guge.sports.entity.Dto.Option;
import com.guge.sports.entity.Dto.StStudentDto;
import com.guge.sports.entity.Dto.StTeacherDto;
import com.guge.sports.entity.StStudent;
import com.guge.sports.service.StDeptService;
import com.guge.sports.service.StStudentService;
import com.guge.sports.toolPackage.base.BaseController;
import com.guge.sports.toolPackage.utils.FileUploadUtils;
import com.guge.sports.toolPackage.utils.MyPager;
import com.guge.sports.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-09-14
 */

@Api(description = "学生接口")
@RestController
@RequestMapping("/sports/st-student")
public class StStudentController extends BaseController<StStudent> {

    @Autowired
    private StStudentService stStudentService;

    @Autowired
    private StDeptService stDeptService;

    @ApiOperation(value = "实际分页查询")
    @PostMapping("/selectStStudentPage")
    public R selectStTeacherPage(MyPager<StStudentDto> myPager, @RequestBody(required = false) StStudentDto entity) {
        System.out.println(entity);
        // 模糊查询
        if (entity.getSname() != null && entity.getSname().length() > 0){
            entity.setSname("%"+entity.getSname()+"%");
        }
        MyPager<StStudentDto> page = stStudentService.selectStTeacherPage(myPager, entity);
        return R.ok().data("page",page);
    }

    // 学生搜索条件渲染
    @ApiOperation(value = "学生搜索条件渲染")
    @GetMapping("/getSearchCondition")
    public R getDeptNameAndDidList(){
        List<Option> depts = stDeptService.getDeptNameAndDidList();
        List<Option> goSchoolYears = stStudentService.getGoSchoolYearList();
        List<Option> goStateTimes = stStudentService.getGoStateTimeList();
        return R.ok().data("depts",depts).data("goSchoolYears",goSchoolYears).data("goStateTimes",goStateTimes);
    }


    @ApiOperation(value = "入学年份条件查询")
    @GetMapping("/getGoSchoolYearList")
    public R getGoSchoolYearList(){
        List<Option> goSchoolYears = stStudentService.getGoSchoolYearList();
        return R.ok().data("goSchoolYears",goSchoolYears);
    }


    // 学生管理数据导出
    @ApiOperation(value = "导出表格")
    @PostMapping("/excelExport")
    public R excelExport(@RequestBody(required = false) StStudentDto entity) {


        return null;
    }

    @ApiOperation(value = "导入图片")
    @PostMapping("/uploadImage")
    public String upload(MultipartFile uploadFile) {
        String s = null;

        s = FileUploadUtils.upload(uploadFile, "image");

        return s;
    }

}

